package com.zynn.common.core.utils;

import com.zynn.common.core.constant.DesConstant;
import org.apache.commons.lang.StringUtils;
import org.bouncycastle.jcajce.provider.symmetric.DES;

import java.net.URLDecoder;

/**
 * @author 杨岳
 * @date 2018/6/28 16:53
 */
public class ParamUtil {

    private static final String UNDEFINED = "undefined";
    private static final String NAN = "NaN";
    private static final String NULL = "null";

    /**
     * 判断参数不为空并且不等于Undefined
     *
     * @param param 请求参数
     * @return true
     */
    public static boolean isEmptyOrUndefined(Object... param) {
        try {
            for (Object s : param) {
                if (StringUtils.isEmpty(s.toString()) || UNDEFINED.equals(s.toString()) || NAN.equals(s.toString()) || NULL.equals(s.toString())) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return true;
        }
        return false;
    }


    /**
     * 检查参数 并转为int
     *
     * @param param 参数
     * @return 讲参数转为int
     */
    public static Integer checkParamToInteger(String param) throws NumberFormatException {
        if (ParamUtil.isEmptyOrUndefined(param)) {
            return 0;
        }
        return Integer.parseInt(param);
    }

    /**
     * 解码并且解密
     *
     * @param param 请求参数
     * @return 解密后的字符串
     */
    public static String decodeAndDecrypt(String param) {
        String result = "";
        //解密
        result = param;
        return result;
    }
}
